package com.ayf.payment.game.api.utils;

import com.alibaba.fastjson.JSON;
import com.swwx.charm.commons.lang.utils.LogPortal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: 排序工具类
 * @Author: zh-liang
 * @Date : 2020-04-10 16:37
 */
public class SortUtils {

    /**
     * 将传进来的字符串进行字典排序，并拼接成一个字符串返回
     *
     * @param obj 字符串
     * @return 排序后的字符串
     */
    public static String dict(Object... obj) {
        LogPortal.info("排序之前[{}]", JSON.toJSONString(obj));
        StringBuilder str = new StringBuilder();
        if (obj.length > 0) {
            List<String> list = new ArrayList<>();
            for (Object o : obj) {
                list.add(o.toString());
            }
            Collections.sort(list);
            for (String s : list) {
                str.append(s);
            }
        }
        LogPortal.info("排序之后[{}]", str.toString());
        return str.toString();
    }
}
